#ifndef GLOBALS_H
#define GLOBALS_H
//******************************************************************************
//*this code is protected by the GNU affero GPLv3
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//*                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
//------------------------------------------------------------------------------
//compiler stuff
//------------------------------------------------------------------------------
#include <stdarg.h>
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//system libs
//------------------------------------------------------------------------------
#include <libudev.h>
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//ulinux stuff
//------------------------------------------------------------------------------
#include <ulinux/compiler_types.h>
#include <ulinux/types.h>
#include <ulinux/types_posix.h>
#include <ulinux/sysc.h>
#include <ulinux/error.h>

#include <ulinux/file.h>
#include <ulinux/stat.h>

#include <ulinux/signal/signal.h>

#include <ulinux/epoll.h>

#include <ulinux/socket/socket.h>
#include <ulinux/socket/un.h>
#include <ulinux/socket/msg.h>

#include <ulinux/mmap.h>

#include <ulinux/ioctl.h>
#include <ulinux/time.h>
#include <ulinux/input/evdev.h>

#include <ulinux/utils/ascii/ascii.h>
#include <ulinux/utils/ascii/string/string.h>
#include <ulinux/utils/ascii/string/vsprintf.h>
#include <ulinux/utils/ascii/string/conv/decimal/decimal.h>
#include <ulinux/utils/ascii/block/conv/decimal/decimal.h>
#include <ulinux/utils/mem.h>
#include <ulinux/utils/maths.h>
#include <ulinux/utils/ascii/match/match.h>

#include "ulinux_namespace.h"
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//si driver things stuff
//------------------------------------------------------------------------------
#include <alga/timing.h>
#include <alga/pixel_fmts.h>
#include <alga/amd/dce6/dce6.h>
#include <alga/amd/si/ioctl.h>
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//protocol
//------------------------------------------------------------------------------
#include <wayland/display.h>
#include <wayland/callback.h>
#include <wayland/compositor.h>
#include <wayland/registry.h>
#include <wayland/shm.h>
#include <wayland/shm_pool.h>
#include <wayland/buffer.h>
#include <wayland/seat.h>
#include <wayland/output.h>
#include <wayland/keyboard.h>
#include <wayland/pointer.h>
#include <wayland/surface.h>
#include <wayland/region.h>
#include <wayland/data_device_manager.h>
#include <wayland/shell.h>
#include <wayland/shell_surface.h>
#include <wayland/wayland.h>
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//our stuff
//------------------------------------------------------------------------------
#define LWL_ERR -1
#define LWL_OK   0

#define cs_n(x) (sizeof(x)-1)
//get the number of dws requiered to fit x
#define DWS_ROUNDUP(x) (((x)&3)?((x)>>2)+1:(x)>>2)

#ifndef QUIET
#ifdef SRV_C
u8 *g_dprintf_buf;
void *g_cfg_path="lwl.conf";
#else
extern u8 *g_dprintf_buf;
extern void *g_cfg_path;
#endif
#define DPRINTF_BUF_SZ 2048
#define PERR(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,fmt,\
##__VA_ARGS__)

#define PERRC(str) {l rl;do rl=ulinux_sysc(write,3,2,str,sizeof(str));\
while(rl==-EINTR||rl==-EAGAIN);}

#ifdef LOG_WIRE_LVL
#define LOG_WIRE(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,\
"wire:" fmt,##__VA_ARGS__)
#else//LOG_WIRE_LVL
#define LOG_WIRE(fmt,...) (void)0;
#endif

#ifdef LOG_UDEV_LVL
#define LOG_UDEV(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,\
 "udev:" fmt,##__VA_ARGS__)
#else//LOG_UDEV_LVL
#define LOG_UDEV(fmt,...) (void)0;
#endif

#ifdef LOG_EVDEV_LVL
#define LOG_EVDEV(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,\
"evdev:" fmt,##__VA_ARGS__)
#else//LOG_EVDEV_LVL
#define LOG_EVDEV(fmt,...) (void)0;
#endif

#ifdef LOG_CFG_LVL
#define LOG_CFG(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,\
"cfg:" fmt,##__VA_ARGS__)
#else
#define LOG_CFG(fmt,...) (void)0;
#endif

#ifdef LOG_LVL
#define LOG(fmt,...) ulinux_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,fmt,\
##__VA_ARGS__)
#else//LOG_LVL
#define LOG(fmt,...) (void)0;
#endif

#else//QUIET
#define PERR(fmt,...) (void)0;
#define PERRC(str) (void)0;
#define LOG_WIRE(fmt,...) (void)0;
#define LOG_UDEV(fmt,...) (void)0;
#define LOG_EVDEV(fmt,...) (void)0;
#define LOG_CFG(fmt,...) (void)0;
#define LOG(fmt,...) (void)0;
#endif

struct rect{
  s32 x;
  s32 y;
  s32 w;
  s32 h;
};

//clients have epoll data.u32 from 0 to CLIENTS_MAX-1
//event devices have epoll data.u32 from CLIENT_MAX to EPOLL_SIGS-1
#define EPOLL_SIGS (CLIENTS_MAX+LINUX_EVDEVS_MAX)
#define EPOLL_SRV (EPOLL_SIGS+1)
#define EPOLL_UDEV (EPOLL_SRV+1)

#include "evdev.h"
#include "udev.h"
#include "client/registry_map.h"
#include "client/shm_pool.h"
#include "client/shm_pool_buffer.h"
#include "client/surface.h"
#include "client/region.h"
#include "client/shell_surface.h"
#include "client/pointer.h"
#include "client/keyboard.h"
#include "client/shell_surface.h"
#include "client/client.h"
#include "registry/display.h"
#include "registry/shm.h"
#include "registry/compositor.h"
#include "registry/data_device_manager.h"
#include "registry/shell.h"
#include "registry/seat.h"
#include "registry/output/layout_row.h"
#include "registry/output/output.h"
#include "registry/output/dce.h"
#include "registry/registry.h"
#include "cfg/cfg.h"
#include "cfg/output/layout.h"
#include "cfg/output/match.h"
#include "cfg/output/mode.h"
#include "cfg/output/output.h"
#include "wire/registry/wl_compositor.h"
#include "wire/registry/wl_display.h"
#include "wire/registry/wl_registry.h"
#include "wire/registry/wl_shm.h"
#include "wire/registry/wl_data_device_manager.h"
#include "wire/registry/wl_shell.h"
#include "wire/registry/wl_seat.h"
#include "wire/registry/wl_output.h"
#include "wire/client/wl_callback.h"
#include "wire/client/wl_region.h"
#include "wire/client/wl_shm_pool_buffer.h"
#include "wire/client/wl_shm_pool.h"
#include "wire/client/wl_surface.h"
#include "wire/client/wl_shell_surface.h"
#include "wire/client/wl_pointer.h"
#include "wire/client/wl_keyboard.h"
//------------------------------------------------------------------------------
#endif
